package com.atzxh.java;

/**
 * @author 小红同学
 * @create 2023-03-22-14:24
 * @description  线程安全懒加载的单例模式
 */
public class Singleton {

    private Singleton(){}

    private static Singleton instance = null;

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized(Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                } else {
                    return instance;
                }
            }
        }
        return instance;
    }
}
